package com.fkframe.codegener.ui;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;

import com.fkframe.codegener.ui.view.EntityGenerView;
import com.fkframe.codegener.ui.view.SingleGenerView;
import com.fkframe.codegener.ui.view.TwoTableGenerView;
//===========================================
//二级菜单响应事件处理  SubMenuActionDo.java
//===========================================
public class SubMenuActionDo implements ActionListener{
	//对应窗体
	EETSoftFrame frame;
	JPanel panel ; 
	ConfigGet con ;
	//==========================
	//函数初始化
	SubMenuActionDo(EETSoftFrame frame){
		this.frame = frame;
		this.panel = frame.panel.m_panel.p_right;
		con = new ConfigGet();
	}
	//==========================
	//事件响应
	//==========================
	public void actionPerformed(ActionEvent e)
	{
		
		//=====================
		//如果是添加
		if(e.getActionCommand().equals("btn_exam_kind")){
			btnExamKindAction();
		}else if(e.getActionCommand().equals("btn_exam_add")){
			btnExamAddAction();
		}else if(e.getActionCommand().equals("btn_entity_genner")){
			toEntityView();
		}else if(e.getActionCommand().equals("btn_single_genner")){
			toSingleView();
		}else if(e.getActionCommand().equals("btn_two_genner")){
			toTwoView();
		}
		
	}
	//===================================
	public void toEntityView(){
		//panel.setPreferredSize(new Dimension(frame.getMinMainBoardWidth() ,400));
		//System.out.println(panel.getWidth()+"=========");
		panel.removeAll();
		panel.repaint();
		//==============================
		EntityGenerView view = new EntityGenerView(frame);
		view.setPreferredSize(new Dimension(panel.getWidth(),panel.getHeight()));
		//view.setBackground(Color.GRAY);
		
		panel.add(view);
		//更新
		frame.validate();
		frame.reDoCommand = "btn_entity_genner" ; //当前存下现在窗体重化执行函数名
	}
	
	public void toSingleView(){
		panel.removeAll();
		panel.repaint();
		
		SingleGenerView view = new SingleGenerView(frame,panel,frame.panel.m_panel.scrollPane.getViewport());
		view.setPreferredSize(new Dimension(panel.getWidth(),panel.getHeight()));
		panel.add(view);
		//更新
		frame.validate();
		frame.reDoCommand = "btn_single_genner" ; //当前存下现在窗体重化执行函数名
	}
	public void toTwoView(){
		panel.removeAll();
		panel.repaint();
		
		TwoTableGenerView view = new TwoTableGenerView(frame,panel,frame.panel.m_panel.scrollPane.getViewport());
		view.setPreferredSize(new Dimension(panel.getWidth(),panel.getHeight()));
		panel.add(view);
		//更新
		frame.validate();
		frame.reDoCommand = "btn_two_genner" ; //当前存下现在窗体重化执行函数名
	}
	
	
	
	//
	public void  btnExamKindAction()
	{
		
		panel.setPreferredSize(new Dimension(frame.getMinMainBoardWidth() ,400));
		//System.out.println(panel.getWidth()+"=========");
		panel.removeAll();
		panel.repaint();
		//==============================
		//这里添加需要对象
		JLabel lb = new JLabel(new ConfigGet().getImgUrl("icon.png"));
		lb.setHorizontalAlignment(0);
		lb.setPreferredSize(new Dimension(panel.getWidth(),200));
		lb.setBorder(BorderFactory.createLineBorder(Color.red));
		lb.setText("测试一下");
		panel.add(lb);
		
		JPanel pl = new JPanel();
		pl.setPreferredSize(new Dimension(panel.getWidth(),200));
		pl.setBackground(Color.pink);
		pl.setLayout(con.getFlowLayout(1, 0, 0));
		panel.add(pl);
		JButton btn = new JButton(con.getImgUrl("mainmenu/btn_exam.png"));
		btn.setPreferredSize(new Dimension(90,30));
		btn.setFocusCycleRoot(false);
		btn.setBorder(null);
		pl.add(btn);
		//更新
		frame.validate();
		frame.reDoCommand = "btnExamKindAction" ; //当前存下现在窗体重化执行函数名
	}
	public void btnExamAddAction()
	{
		panel.setPreferredSize(new Dimension(frame.getMinMainBoardWidth() ,500));
		panel.removeAll();
		panel.repaint();
		//==============================
		//这里添加需要对象
		//列表
		JTable jTable ;
		//列名内容
		Vector<String> vcol=new Vector<String>();
		Vector<Vector<String>> vrow=new Vector<Vector<String>>();
		
		vcol.addElement("考生编号");
		vcol.addElement("考生姓名");
		vcol.addElement("考生性别");
		vcol.addElement("准考证号");
		vcol.addElement("所在班级");
		vcol.addElement("选择");
		vcol.addElement("填空");
		vcol.addElement("判断");
		vcol.addElement("简答");
		vcol.addElement("操作");
		vcol.addElement("总 成 绩");
		vcol.addElement("全班排名");
		vcol.addElement("年级排名");

		for(int i=1;i<=200;i++)
		{
			Vector<String> temp=new Vector<String>();
			//for(int j=0;j<5;j++)
			//{
				//temp.addElement("2005010720");
			//}
			temp.addElement(i+"");
			temp.addElement("李建东");
			temp.addElement("男");
			temp.addElement("2005010720");
			temp.addElement("05软件四班");
			temp.addElement("20");
			temp.addElement("18");
			temp.addElement("40");
			temp.addElement("30");
			temp.addElement("40");
			temp.addElement("60");
			temp.addElement("190");
			temp.addElement(i+"");
			temp.addElement("30");
			vrow.add(temp);
		}
		jTable=new JTable(vrow,vcol);

		jTable.setAutoscrolls(true);
		jTable.setFocusable(false);
		jTable.setColumnSelectionAllowed(false);
		jTable.setGridColor(Color.black);
		//jTable.setRowSelectionAllowed(false);
		jTable.setRowHeight(22);
		jTable.setAutoResizeMode(0);
		//jTable.setValueAt("妈的", 2, 5);
		//滚动面板
		//JScrollPane jScrollPane=new JScrollPane();
		frame.panel.m_panel.scrollPane.getViewport().add(jTable);
		//frame.panel.m_panel.scrollPane.getViewport().add(jTable);
		//jScrollPane.setPreferredSize(new Dimension(panel.getWidth(),panel.getHeight()-50));
		
		//panel.add(jScrollPane);
		//frame.panel.m_panel.scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
		//更新
		frame.validate();
		frame.reDoCommand = "btnExamAddAction" ; //当前存下现在窗体重化执行函数名
		/*
		private void printTable() {
		Toolkit kit = Toolkit.getDefaultToolkit(); //获取工具箱
		Properties props = new Properties();
		props.put("awt.print.printer", "durango"); //设置打印属性
		props.put("awt.print.numCopies", "2");

		if (kit != null) {
		//获取工具箱自带的打印对象
		PrintJob printJob = kit.getPrintJob(this, "打印 页面", props);

		if (printJob != null) {
		Graphics pg = printJob.getGraphics(); //获取打印对象的图形环境
		Graphics2D g2 = (Graphics2D) pg; ///
		PageFormat pf = new PageFormat(); ///
		g2.translate(pf.getImageableX(), pf.getImageableY()); ///转换坐标，确定打印边界
		if (pg != null) {
		  try {
		    pg.dispose(); // Shoot the page to printer
		    this.jScrollPane14.printAll(pg); //打印该窗体的组件
		  }
		  finally {
		    pg.dispose(); //注销图形环境pageIndex
		  }
		}
		printJob.end(); //结束打印作业
		}
		}
		}
		import   java.awt.Graphics;   
  import   java.awt.print.*;   
    
  import   javax.swing.*;   
  /**   
    *   <p>Title:   </p>   
    *   <p>Description:   </p>   
    *   <p>Copyright:   Copyright   (c)   2003</p>   
    *   <p>Company:   </p>   
    *   @author   not   attributable   
    *   @version   1.0   
   
    
  public   class   PrinterTest   implements   Printable   {   
    
      JComponent   component   ;   
      private   PrinterTest()   {   
      }   
    
  //自己调整页面   
      public   int   print(Graphics   graphics,   PageFormat   pageFormat,   int   pageIndex)   throws   PrinterException   {   
    
          if(pageIndex>=1)   
              return   Printable.NO_SUCH_PAGE;   
    
          component.paint(graphics);   
    
            return   Printable.PAGE_EXISTS;   
    
      }   
    
      private   void   setTable(JTable   tb){   
        component=tb;   
      }   
    
    
      public   static     void   printTable(JTable   tb){   
          PrinterTest   test   =   new   PrinterTest();   
          test.setTable(tb);   
          PrinterJob   job   =   PrinterJob.getPrinterJob();   
    
          job.setPrintable(test);   
          try{   
              job.print();   
          }catch(PrinterException   e){   
              e.printStackTrace();   
          }   
    
      }
		 */
	}
}